﻿using RAP.Framework.Libary.DomTemplateBuilder.Element;
using RAP.Framework.Libary.DomTemplateBuilder.Interface;

namespace RAP.Framework.Libary.DomTemplateBuilder.Handler
{
	public class PropertyElementHandler : ExpressionValueHandler
	{
		/// <summary>
		/// 获取属性名称
		/// </summary>
		/// <returns></returns>
		protected virtual string Property
		{
			get
			{
				PropertyElement ele = Element as PropertyElement;
				return ele.Property;
			}
		}

		protected override string FieldName
		{
			get
			{
				return Property;
			}
		}

		/// <summary>
		/// 获取属性的值
		/// </summary>
		/// <param name="rootParamObject"></param>
		/// <param name="parentParamObject"></param>
		/// <param name="context"></param>
		/// <returns></returns>
		public virtual object GetPropertyValue ( object rootParamObject, object parentParamObject, ITemplateRenderContext context )
		{
			return GetFieldValue ( rootParamObject, parentParamObject, context );
		}

		/// <summary>
		/// 获取属性的值
		/// </summary>
		/// <param name="propertyName"></param>
		/// <param name="rootParamObject"></param>
		/// <param name="parentParamObject"></param>
		/// <param name="context"></param>
		/// <returns></returns>
		public virtual object GetPropertyValue ( string propertyName, object rootParamObject, object parentParamObject, ITemplateRenderContext context )
		{
			return GetFieldValue ( propertyName, rootParamObject, parentParamObject, context );
		}

		/// <summary>
		/// 获取属性名称
		/// </summary>
		/// <param name="propertyName"></param>
		/// <param name="rootParamObject"></param>
		/// <param name="parentParamObject"></param>
		/// <param name="context"></param>
		/// <returns></returns>
		public virtual string GetPropertyName ( string propertyName, object rootParamObject, object parentParamObject, ITemplateRenderContext context )
		{
			return GetFieldName ( propertyName, rootParamObject, parentParamObject, context );
		}

		public virtual string GetPropertyName ( object rootParamObject, object parentParamObject, ITemplateRenderContext context )
		{
			return GetFieldName ( rootParamObject, parentParamObject, context );
		}
	}
}
